package com.office.personalOffice.nameCard.nameCardList.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.office.personalFolders.myFolder.pojo.OaFolder;
import com.office.personalOffice.personalInfo.model.TbStaff;
import com.office.personalOffice.nameCard.nameCardList.dao.IsNameCardListDao;
import com.office.personalOffice.nameCard.nameCardList.pojo.OaNamecard;
import com.office.personalOffice.nameCard.nameCardList.pojo.OaNamecardlist;
import com.office.personalOffice.nameCard.nameCardList.service.IsNameCardListService;
import com.office.personalOffice.nameCard.personalNameCard.service.IsPNCService;
import com.office.util.PageModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @project_name: OA
 * @description:
 * @author: LaoWang
 * @date: 2022/11/1 18:32
 */

@Service
public class nameCardListService implements IsNameCardListService {

    @Autowired
    private IsNameCardListDao isNameCardListDao;

    @Autowired
    private IsPNCService isPNCService;

    public IsNameCardListDao getIsNameCardListDao() {
        return isNameCardListDao;
    }
    public void setIsNameCardListDao(IsNameCardListDao isNameCardListDao) {
        this.isNameCardListDao = isNameCardListDao;
    }



    /**
     * 根据名片夹分类名查询用户所有名片夹（名片夹分类模块调用）
     * @param oaNamecardlist 查询条件
     * @return 名片夹信息集合
     */
    public List<OaNamecard>  getAllNamecardByName(OaNamecardlist oaNamecardlist){
        return isPNCService.getAllNamecardByName(oaNamecardlist);
    }




    /**
     * 根据条件查询所有名片夹分类集合(去重)
     * @param oaNamecardlist 查询条件
     * @return 名片夹分类集合
     */
    public List<OaNamecardlist> getOaNamecardlistByOaNamecardlist(OaNamecardlist oaNamecardlist){
        return isNameCardListDao.getOaNamecardlistByOaNamecardlist(oaNamecardlist);
    }

    /**
     * 根据条件查询所有名片夹分类集合
     * @param oaNamecardlist 查询条件
     * @return 名片夹分类集合
     */
    public List<OaNamecardlist> getRecordByOaNamecardlist(OaNamecardlist oaNamecardlist){
        return isNameCardListDao.getRecordByOaNamecardlist(oaNamecardlist);
    }

    //名片夹类名称验证
    public String nameYZ(OaNamecardlist oaNamecardlist,HttpSession session){
        TbStaff staff1 = (TbStaff) session.getAttribute("loginUser");
        oaNamecardlist.setNamecardlistMaillistId(staff1.getId().toString());
        oaNamecardlist.setNamecardlistUsable(1);
        List<OaNamecardlist> oa = isNameCardListDao.getOaNamecardlistByOaNamecardlist(oaNamecardlist);
        if(oa!=null && oa.size()>0){
            return "true";
        }else {
            return "false";
        }

    }



    //添加名片夹分类
    public String addNameCardList(OaNamecardlist oaNamecardlist, HttpSession session){
        TbStaff staff1 = (TbStaff) session.getAttribute("loginUser");
        oaNamecardlist.setNamecardlistMaillistId(staff1.getId().toString());
        oaNamecardlist.setNamecardlistUsable(1);
        oaNamecardlist.setNamecardlistCreatetime(new Date());
        Integer integer = isNameCardListDao.addOaNamecardlist(oaNamecardlist);
        if(integer==1){
            return "true";
        }else {
            return "false";
        }
    }


    //修改名片夹分类（更名）
    public String updateName(OaNamecardlist oaNamecardlist){
        oaNamecardlist.setNamecardlistUpdatetime(new Date());
        Integer integer = isNameCardListDao.updateNameOaNamecardlist(oaNamecardlist);
        if(integer==1){
            return "true";
        }else {
            return "false";
        }
    }


    //修改名片夹分类（删除即更改可用状态）
    public String delete(OaNamecardlist oaNamecardlist){
        oaNamecardlist.setNamecardlistUsable(1);
        List<OaNamecardlist> recordByOaNamecardlist = getRecordByOaNamecardlist(oaNamecardlist);
        oaNamecardlist.setNamecardlistName("我的名片夹");
        oaNamecardlist.setNamecardlistUpdatetime(new Date());
        String flag="true";
        for (OaNamecardlist namecardlist : recordByOaNamecardlist) {
            oaNamecardlist.setNamecardlistId(namecardlist.getNamecardlistId());
            Integer integer = isNameCardListDao.updateNameOaNamecardlist(oaNamecardlist);
            if(integer!=1) {
                flag="false";
            }
        }
        if(flag.equals("true")){
            return "true";
        }else {
            return "false";
        }
    }




}
